<?php 
ob_start();
include 'connect.php';

if ($_GET['action']=='login'){
 	$query = mysql_query("select * from room where rname='{$_POST['uname']}' && rid='{$_POST['password']}' and role like '{$_POST['role']}'");
	if ($rows=!mysql_fetch_array($query,MYSQL_ASSOC)){
 		echo "<script type='text/javascript'>alert('登录失败!');history.back();</script>";
 	}
  	else{

      if($_POST['role']=="学生"){
		setcookie('username',$_POST['uname']);
		echo "<script type='text/javascript'>alert('登录成功');window.location.href='student/admin.php';</script>"; 

	  }
	  else{

		setcookie('username',$_POST['uname']);
		echo "<script type='text/javascript'>alert('登录成功');window.location.href='admin/admin.php';</script>"; 

	  }

  	
  	}
}
?>